using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace Universe.CrossIO.Test
{
    class MyTemp: IDisposable
    {
        private string _folder;
        public MyTemp()
        {
        }


        public string Folder
        {
            get
            {
                if (_folder == null)
                    lock(this)
                        if (_folder == null)
                        {
                            _folder =
                                Path.Combine(
                                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                    "Temp\\Universe.CrossIO.Test\\" + Guid.NewGuid());

                            try {
                                Directory.CreateDirectory(_folder); }
                            catch
                            {
                            }


                        }

                return _folder;
            }
        }

        public string this[string file]
        {
            get
            {
                return Path.Combine(Folder, file);
            }
        }


        public void Dispose()
        {
            try
            {
#if DEBUG
                FileSystemKiller.DeleteFolderOnReboot(_folder);
#else
                FileSystemKiller.DeleteFolder(_folder);
#endif
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Failed to dispose. " + Environment.NewLine + ex);
            }
        }
    }
}
